
/*
*Pool Public Licence version 0.1 or later
*Released on 20th April 2008.
*Any voilations can be repoted at paritosh@wikiocean.net
*What is treated as voilations can be found at www.wikiocean.net/ppl1-voilations* 
******************************************************************************
* The contents of this file are subject Affero GPL v3 and later with additional conditions.
* The additional conditions are to be considered as part of the Affero GPL v3 and later.
* The additional conditions will supersede the Affero GPLv3 and later in case of conflict.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.gnu.org/licenses/agpl.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya.
* created by Paritosh Pungaliya are Copyright (C) Paritosh Pungaliya; All Rights Reserved.
* Contributions are Copyright (C) 2001-2008 Paritosh Pungaliya.

* Objective of the additional terms (license) 
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencie(s).
* 3) To avoid a situation where big corporates or investors can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the openness changes in companies that get Venture Capital funding.)
* (if you agree to this logic I invite you to our group to work together)

* Additional conditions
*  0) Source code will also include
* 	a) data dictionaries, data ontologies which are used to alter the behavior of code or to control           the features of application.
* 	b) Any code generated or derived automatically or manually from this code or logic
*  1) The revenue generated by deploying, implementing , selling services and other activities
*  	 based on this source code should be shared 100%, between the people working on it.
*  2) Capital invested should be given only fixed rate of return or linked to revenue/surplus growth for limited time.
*  3) People working on the project should always have an option to replace the capital provider in full or part with lower cost capital.
*  4) Their should not be any ownership which can be sold as a claim on future profit to be generated from the work of people working on the code.
*  5) Brand thus generated should belong to the group.
*  6) For old and new members revenue sharing should be equal for same work equivalent.
*  7) The share of revenue should be decided by bidding for work before allocation of work within the group.
*  8) Before bidding various method of measuring the work should be clearly defined and published in public domain. Any change in process should also be publised in public domain imediately.
*  9) All data related to to revenue sharing should be published as and when generated in public domain.
*  10) For group of people having size more than 10 people will have to make it open online for others to participate in bids. 
*  11) All people involved in related and sub project will be treated as a group.
*  12) Once this license is being used for a certain code then all and any other software services being provided by the group should complusorilly come under 100% revenue sharing.
*  13) Cross subsidization should not happen under this revenue share, no additional benefit should be drawn from the people, by the employing agency.
*  14) Any position or knowledge or legal structure created relating to people working on code, which adversely affects the spirit of 100% revenue share will be treated as a violation.
*  15) Revenue sharing defined.
*     a) includes direct revenue and also intangible gains like brand, and organization.
*     b) No personal judgment should be involved in judging the distribution of revenue.It has to be pre-defined formula based.
*     c)100% of revenue should be shared before expenses and recievers should have control over what expenses to incur.
*     d)For the work done in any month by contributing group member, working on any project can be given revenue share from the work done by the group, for a maximum of 18 months after that month.
*     e)Revenue should be apportioned to the month in which work is done and not when received.
*  The group fulfilling the above conditions also has to be a wiki ecosystem further defined in www.wekosystem.org or read about Wekosystem at www.wikiocean.net

*  ******************************************************************************
*/  
package pool.tablename;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Hashtable;
//import java.util.Map;
import java.util.Vector;

import control.RequestParameter;

import pool.preprocess.Preprocess;
import basicprocess.Basicprocess;


import timer.ExecutionTimer;
import timer.TimerRecordFile;

import utility.ConvertToLower;


import utility.MessageGenerator;

import dbmanager.ChekInMaster;
import dbmanager.DBManager;
import dbmanager.GetIdName;

/**
 * 
 * @author Administrator
 *Transaction_details class do the insertion for item which is present
 *in given message and Updation,Deletion and view operation for the item
 *which is presents in a Transaction_details.  
 *Transaction_details contains the following fields:
 *id  stores id of transaction_details table,
 *Tid  stores id of transaction table.
 *Item  stores id of item from master table for which request is sent.
 *Qty stores quantity given in request for particular item.
 *Rate stores rate for particular item.
 *Amount stores total amount.
 */
public class Transaction_details extends SubPool
{
	
	public Hashtable<Object,Object> TransactionMap = new Hashtable<Object,Object>();
	
	public Hashtable<Object,Object> TransMap = new Hashtable<Object,Object>();
	public Hashtable<Object,Object> TransactionDetailMap = new Hashtable<Object,Object>();
	
	public Vector<Object> PropertyList =  new Vector<Object>();
	public Vector<Object> TPlPropertyList =  new Vector<Object>();
	public Td_property_details tdpd;
	
	private String tid="no$";
	private String td_tableName = "transaction_details";
	private String masterTable = "transaction";	
	private String tdpl_tableName = "td_property_details";	
	//private String spChar="";	
	//private String MESSAGE;
	private Vector<Object> OldTransDetailVector  = new Vector<Object>();
	private Vector<Object> NewTransDetailVector = new Vector<Object>();
	public boolean directRequest=false;
	boolean flagResult = false;
	
	private Hashtable<Object,Object> ViewHashtable = new Hashtable<Object, Object>();
	
	public Transaction_details(DBManager sqldb)
	{	
		ExecutionTimer t = new ExecutionTimer();
		t.start();
		this.sqlDB = sqldb;
		gin = new GetIdName(sqldb);
		tdpd=new Td_property_details(sqldb);
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","Transaction_details",t.duration());
	}
	
	
	public Transaction_details(DBManager sqldb,String msg,String process,String Request)
	{
		ExecutionTimer t = new ExecutionTimer();
		t.start();
		this.Request = Request;
		this.process = process;
		this.sqlDB = sqldb;
		message = msg;	
		gin = new GetIdName(sqldb);
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","Transaction_details",t.duration());
	}
	
	
	public Transaction_details(){
	}
	

		 
	 /**
	 * getInsert method inserts tempProperty1 in a  Transaction_details table
	 * which contains all the fields of Transacyion_details presents in a
	 * given message e.g.tid,item,qty,rate.
	 * For getInsert method of Transaction pass a table name and hashtable as a 
	 * parameter. This method is invoked by the object of DBManager i.e sqlDB. 
	 * It  create object of  Transaction_details and invokes the method 
	 * initTransaction_details of Transaction_details for the items.
	 * 
	 */	
		public StringBuffer getInsert()
	    {
			ExecutionTimer t = new ExecutionTimer();
			t.start();
			
		     String id = null;
		     ChekInMaster check = new ChekInMaster(sqlDB);
		     TransactionDetailMap.clear();
		     transactionPreProcess();
		      try
		        {
		          for(int i = 0; i < PropertyList.size(); i++)
		            {
		        	  Transaction_details td = (Transaction_details)PropertyList.get(i);
		        	   TransactionDetailMap.putAll(td.TransactionDetailMap);
		        	   
		            	Hashtable<Object,Object> tempProperty1 = new Hashtable<Object,Object>();
		                tempProperty1.putAll(TransactionDetailMap);
		                tempProperty1.put("tid", tid);
		              	if(tid.equals("no$"))
		              	{
		              		sbrDTB.append(" pool::Transaction_Details ::getInsert():: insert tid properly ");
		              		flagResult = false;
							return sbrDTB;
		              	}
		            
		                ////////////////////////////////////
		               // tempProperty1.put("amount", Integer.valueOf(0));
		               // tempProperty1.put("rate", Integer.valueOf(0));
		    	        //////////////////////////////////////
		    	       
		                //ResultSet rs = sqlDB.getSelect("Select * from transaction_details where id = 1");
		        		//-------------------------------
		                // add property into tdpl if it not present in td
		              //  ResultSet rs1 = sqlDB.getSelect("SELECT fieldname FROM command where msgtype = 'transaction_details' and process = 'add'");
		    			Vector<Object> columnname =sqlDB.getSelect("SELECT * FROM transaction_details where id = 1",'1');
		    			/*while(rs1.next())
		    			{
		    				String colname  = rs1.getString("fieldname").toLowerCase();
		    				columnname.add(colname);
		    			}*/
		    		//	rs1 = null;
		        		try 
		        		{	
		        			Enumeration<Object> iter = tempProperty1.keys();
		        			while(iter.hasMoreElements())
		        			{
		        				String col = iter.nextElement().toString();
		        				if(columnname.contains(col)==false)
		        				{
		        					Td_property_details tdpd = new Td_property_details(sqlDB,tdpl_tableName,process,Request);
		        					tdpd.PropertyMap.put("pid",gin.getId(col));
		        					String value = gin.getId(tempProperty1.get(col).toString());
		        					if(value.equals("0"))
		        						tdpd.PropertyMap.put("vt",tempProperty1.get(col).toString() );
		        					else
		        						tdpd.PropertyMap.put("pv", value);
		        					td.tdpd.TdPropertyList.add(tdpd);
		        					tempProperty1.remove(col);
		        				}
		        			}
		        		} 
		        		catch (Exception e) 
		        		{
		        		} 
		        		
		                if(tempProperty1.get("qty").toString().equals(""))
		                {
		                	//tempProperty1.put("qty", 1);
		                }
		                if(tempProperty1.get("qty").toString().equals("0"))
		                {
		                	tempProperty1.put("ErrorInput","Please insert valid qty");
		                	flagResult = false;
		                	return new StringBuffer(tempProperty1.toString());
		                }
		                if(tempProperty1.get("item").toString().equals("0"))
		                {
		                	tempProperty1.put("ErrorInput","Please insert valid Item");
		                	flagResult = false;
		                	return new StringBuffer(tempProperty1.toString());
		                }
		                tempProperty1=gin.convertMasterId(tempProperty1, td_tableName,process);
		                if(check.isInProperty_details(tempProperty1,td_tableName) == false)
						{	

		            			 try
				                {
				                    ResultSet rs = sqlDB.getSelect((new StringBuilder("select id from max_id_table where table_name = '")).append(td_tableName).append("'").toString());
				                    rs.next();
				                    id = rs.getString("id");
				                    tempProperty1.put("id", id);
				                    rs.close();
				                }
				                catch(Exception e)
				                {
				                    e.printStackTrace();
				                }
				                if(directRequest)
				                {
				                	TransactionMap = gin.ConvertvalueToMasterId(TransactionMap, process, "transaction");
				                	TransMap = gin.ConvertvalueToMasterId(TransMap, process, "transaction");
				                	sqlDB.getUpdate(masterTable, TransactionMap, TransMap);
				                }	
			                	int j = sqlDB.getInsert(td_tableName, tempProperty1);
								if(j>0)
								{	
									flagResult = true;
				                    sqlDB.getUpdate((new StringBuilder("update max_id_table set id ='")).append(Integer.parseInt(id) + 1).append("' where table_name ='").append(td_tableName).append("'").toString());
				                    
				                    sbrDTB.append(" Following Transaction_Detail is Added..."+tempProperty1.toString());
				                    
				                    td.tdpd.setTdid(id);
				                    td.tdpd.flagResult = flagResult;
				                    sbrDTB.append(td.tdpd.getInsert());
				                    
				                   // tdVector.add(tempProperty1); // It will create the vector for the Reports class.
				                    
				                  // 	flagReport = true;		
				                   	sqlDB.pLog.Logger.append("\n "+ Request +" Added Success fully........ ");	
				                	
				                	
				                	strID = id;
				                	flagResult = td.tdpd.boolTdpdSetCommit;	          	
					                
								}
								else
								{	
									sbrDTB.append(" pool::Transaction_Details ::getInsert():: Error..");
									flagResult = false;
									return sbrDTB;
								}
								
								if(flagResult == true)
									continue;
								else
									break;
						}
						else
						{
							sbrDTB.append(" pool::Transaction_Details ::getInsert():: Item Already exist ");
							flagResult = false;
							return sbrDTB;
						}
		                
		            }
		          
		          /*if(flagReport == true)
		          {
		          		setVector(oldVector, tdVector);
		          		Request = td_tableName;
		          		getReport();
		          }*/
		          /* try 
		  		{
		  			//Add Transsaction Details to reportMaster
		  			String trans_type = getType();
		  			ResultSet reportRS = sqlDB.getSelect("select PV from property_details where pid="+gin.getId("Report")+" and mid ="+trans_type);
		  			while(reportRS.next())
		  			{
		  				String reportName = reportRS.getString("PV");
		  				//INSERTED INTO REPORT_MASTER
		  				sqlDB.getInsert("insert into report_master(tid, reportOn, process, report_name) values("+id+", '"+trans_type+"', '"+"mod"+"', '"+gin.getItem(reportName)+"')");
		  			}
		  			//INSERTING IN PROCESS LOGGER
					ProcessLogger procLogger = new ProcessLogger(sqlDB);

					//UPDATING IN PROCESS LOGGER
					try
					{
						//procLogger.addLog(id, trans_type, process, Request, message,username);
					}
					catch (Exception e) {
					}
					procLogger.updateLog(id, "0",trans_type.toString(), "5");
		  		}
		  		catch (Exception e) 
		  		{
		  			e.printStackTrace();
		  		}*/
		        }
		        catch(Exception e)
		        {
		            e.printStackTrace();
		        }
		       // sbrDTB.append(" Inserted in TD ");
		        t.end();
				@SuppressWarnings("unused")
				TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","getInsert",t.duration());
		        return sbrDTB;
		    }
	
	
		public StringBuffer getUpdate() 
		{
			ExecutionTimer t = new ExecutionTimer();
			t.start();
		   Vector<Object> Tdfield  =new  Vector<Object>();
		   
		   try 
		   {
			ResultSet rs=sqlDB.getSelect("select fieldname from command where msgtype like 'transaction_details' and process='add' and isField='yes'");
			   while(rs.next())
			   { 
				  Tdfield.add(rs.getString("fieldname"));  
			   }
		   } 
		   catch (Exception e1) 
		   {
			e1.printStackTrace();
		   }
	       ChekInMaster check = new ChekInMaster(sqlDB);
	       
	       
	       for(int i = 0; i < NewTransDetailVector.size();i++ )
	       {  
	    	   	   boolean checkflag = false;
		    	   Hashtable<Object,Object> newTransactionMap = new Hashtable<Object,Object>(); /** It will get stores new mesage for Update.*/
		           Hashtable<Object,Object> oldTransactionMap = new Hashtable<Object, Object>(); /** It will get stores old mesage for Update.*/
		           Vector<Object> newTdplVector = new Vector<Object>();
		           Vector<Object> oldTdplVector = new Vector<Object>();
		    	   try
					{
						oldTransactionMap = (Hashtable<Object, Object>)OldTransDetailVector.get(i);
						newTransactionMap = (Hashtable<Object, Object>)NewTransDetailVector.get(i);
					}
					catch (Exception e)
					{
						newTransactionMap = (Hashtable<Object, Object>)NewTransDetailVector.get(i);
						oldTransactionMap.put("tid", newTransactionMap.get("tid"));
						oldTransactionMap.put("pid", newTransactionMap.get("pid"));
					}
					String tdid="";
					try 
					{
						ResultSet rs =sqlDB.getSelect("Select id from "+td_tableName+" where tid='"+tid+"'");
						if(rs.next())
						{
							tdid = rs.getString("id");
						}
					} catch (Exception e1)
					{
						e1.printStackTrace();
					}
					Enumeration<Object> enume = newTransactionMap.keys();				
					while(enume.hasMoreElements())
					{
						String key = enume.nextElement().toString();
						if(!Tdfield.contains(key))
						{
							Hashtable<Object, Object> Tdplmap = new Hashtable<Object, Object>();
							String value = newTransactionMap.get(key).toString();
							value = gin.getId(value);
							if(value.equals("no$"))
							{	
								value = newTransactionMap.get(key).toString();
								Tdplmap.put("vt", value);
							}
							else
								Tdplmap.put("pv", value);
							newTransactionMap.remove(key);
							key= gin.getId(key);
							Tdplmap.put("pid", key);
							Tdplmap.put("tdid", tdid);
							newTdplVector.add(Tdplmap);
							
						}	
					}
					enume = oldTransactionMap.keys();
					while(enume.hasMoreElements())
					{
						String key = enume.nextElement().toString();
						if(!Tdfield.contains(key))
						{
							Hashtable<Object, Object> Tdplmap = new Hashtable<Object, Object>();
							String value = oldTransactionMap.get(key).toString();
							value = gin.getId(value);
							if(value.equals("no$"))
							{	
								value = oldTransactionMap.get(key).toString();
								Tdplmap.put("vt", value);
							}
							else
								Tdplmap.put("pv", value);
							oldTransactionMap.remove(key);
							key= gin.getId(key);
							Tdplmap.put("pid", key);
							Tdplmap.put("tdid", tdid);
							oldTdplVector.add(Tdplmap);
						}	
					}
					try 
					{
					  	Hashtable<Object, Object> temp = new Hashtable<Object, Object>();
					  	Hashtable<Object, Object> temp1 = new Hashtable<Object, Object>();
		          		try 
						{
		          			temp = sqlDB.getSelectCheck(oldTransactionMap,td_tableName);
							if (temp.containsKey("Error")) 
							{
								flagResult = false;
								return new StringBuffer(temp.toString());
							}
							temp = ConvertToLower.convertHashKey(temp);
						} catch (Exception e) {
						}
					  	temp1.putAll(temp);
					  	temp1.putAll(oldTransactionMap);
						oldTransactionMap = temp1; 
							
		            	temp.putAll(newTransactionMap);
		            	newTransactionMap.clear();
		            	newTransactionMap.putAll(temp);
		            }
					catch (Exception e){}
					
					if (check.isInProperty_details(oldTransactionMap,td_tableName) == false)
					{	
						for(int j=0;j<oldTdplVector.size();j++)
						{
							Hashtable<Object, Object> tdplmap =(Hashtable<Object, Object>) oldTdplVector.get(j); 
							if (check.isInProperty_details(tdplmap,tdpl_tableName) == false)
							{
								checkflag =true;
								sbrDTB.append("Old Property Not Present ");
								System.out.println("Old Property Not Present ");
								sqlDB.pLog.Logger.append("\n Old Property Not Present ");
								flagResult = false;
							}
						}
						if(checkflag)
						{
							sbrDTB.append("Old Property Not Present ");
							System.out.println("Old Property Not Present ");
							sqlDB.pLog.Logger.append("\n Old Property Not Present ");
							flagResult = false;
						}	
					}
					if (check.isInProperty_details(newTransactionMap,td_tableName) == true)
					{
						
						for(int j=0;j<newTdplVector.size();j++)
						{
							Hashtable<Object, Object> tdplmap =(Hashtable<Object, Object>) newTdplVector.get(j); 
							if (check.isInProperty_details(tdplmap,tdpl_tableName) == true)
							{
								checkflag =true;
								sbrDTB.append("Old Property Not Present ");
								System.out.println("Old Property Not Present ");
								sqlDB.pLog.Logger.append("\n Old Property Not Present ");
								flagResult = false;
							}
						}
						if(checkflag)
						{
						sbrDTB.append(" pool::PropertyDetails ::getUpdate()::new Property are Present  ");
						System.out.println("pool::PropertyDetails ::getUpdate()::  new Property are Present ");
						sqlDB.pLog.Logger.append("\n new Property are Present ");
						flagResult = false;
						}
					}
					
		            if((check.isInProperty_details(newTransactionMap,td_tableName) == false && check.isInProperty_details(oldTransactionMap,td_tableName) == true ) || checkflag==false)
					{	
		            	
		                ////////////////////////////////////
		            	//newTransactionMap.put("amount", Integer.valueOf(0));
		            	//newTransactionMap.put("rate", Integer.valueOf(0));
		    	        //////////////////////////////////////
		    	       
		                
		           		int j=sqlDB.getUpdate(Request, newTransactionMap, oldTransactionMap);
		           		if(j>0 || !checkflag)
			       		{
		           			if(newTdplVector.size()>0)
		           			{
			           			Td_property_details tdpl = new Td_property_details(sqlDB);
			           			tdpl.setRequestParameter(reqParam);
			           			tdpl.setNewPropertyVector(newTdplVector);
			           			tdpl.setOldPropertyVector(oldTdplVector);
			           			tdpl.getUpdate(); 
		           			}
			       			sqlDB.pLog.Logger.append("\n "+ Request +" updated Success fully........ ");						
							sbrDTB.append(" Following transaction_details is updated... "+newTransactionMap.toString());
							
							strID =  oldTransactionMap.get("tid").toString();
							flagResult = true;			
			       		}
		           		else
						{
							System.out.println("pool::Transaction_details::getUpdate():: Unable to Update........");
							sbrDTB.append(" Unable to Update ");
							flagResult = false;
						}
						
						if(flagResult == true)
							continue;
						else
							break;
		           		/*oldTransactionMap.put("id",oldTransactionMap.get("tid"));
		           		newTransactionMap.put("id",newTransactionMap.get("tid"));
		           		
		           		pdbsOldVector.add(oldTransactionMap); // It will create the vector for the Old property.
		    			pdbsNewVector.add(newTransactionMap); // It will create the vector for the New property.
		    		    			
		    			flagReport = true;*/
		           		
		          }	
		            else
					{
						System.out.println("pool::Transaction_details::getUpdate():: Unable to Update. old property is not present ");
						sbrDTB.append("Unable to Update. old property is not present .");
						flagResult = false;
					}
		           
		       /*if(flagReport == true)
				{
					setVector(pdbsNewVector, pdbsOldVector);
					Request = td_tableName;
					getReport();*/
					/*PropertyDetailsBasicReports pdbs = new PropertyDetailsBasicReports(pdbsOldVector,sqlDB,process);
					pdbs.updateReport(pdbsNewVector);
				}*/
			}
	        t.end();
			@SuppressWarnings("unused")
			TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","directUpdate",t.duration());
	        return sbrDTB;
		
		}
		
	
	@SuppressWarnings("unchecked")
	@Override
		public StringBuffer getView()
	{
		
		ExecutionTimer t = new ExecutionTimer();
		t.start();
		
		StringBuffer sbrProperty=new StringBuffer();
		MessageGenerator msg=new MessageGenerator(sqlDB);
		String mastermsg="";			
		
		//TransMap is set from the transation table which contain an id of transaction only if the request is for  transaction 
		//and there is a direct request to the transaction_details then it shows empty TransMap. 
				
		TransactionDetailMap.putAll(ViewHashtable);
		Hashtable<Object, Object> TradMap= new Hashtable<Object, Object>();
		TradMap.putAll(TransactionDetailMap);
		TradMap=gin.removeDuplFromhash(TransMap,TradMap);
		
		//removed the fields through the TransactionMap which is already presents in the TransMap  through the removeDuplFromhash method.
					
		Hashtable<Object, Object> MastrMap= new Hashtable<Object, Object>();
		if(TradMap.isEmpty()==false)
		{
			
			MastrMap.putAll(TransactionDetailMap);
			
			if(MastrMap.containsKey("tid"))
			{
				MastrMap.put("id", MastrMap.get("tid"));
				MastrMap.remove("tid");				
			}			
		}		
		
		//Master contain an tid in case of direct request to the transaction_details and shows empty in case of request is 
		//through the transaction.		
		
		mastermsg=msg.MasterMessage(masterTable, MastrMap, process);			
		
		//According to the TransactionDetailMap getSelectVector method checks the condition ,searches all the record 
		//in transaction_details table  and stores into the vrs vector.
				
		Vector<Object> vrs  = new Vector<Object>(); 
			vrs.addAll(sqlDB.getSelectVector(TransactionDetailMap, td_tableName));			 
	
		String tdid="";
		
		//For the wrong input to the trans_property_details request it shows empty records.
		
		if(vrs.isEmpty())
		{
			sbrProperty.append("Record not available");
			return sbrProperty;
		}
		StringBuffer Field =new StringBuffer();
		Vector<Object> Heading = new Vector<Object>();
		StringBuffer heading = new  StringBuffer();
		for(int i=0;i<vrs.size();i++)
		{
				
				String presentproperty="";
				Hashtable<Object, Object> hashobj=new Hashtable<Object, Object>();
				hashobj=(Hashtable<Object, Object>) vrs.get(i);
				
				//hashobj contain whole record (e.g tid,item,rate,qty,amount) which has taken through the database 
				//or transaction_details table according to the condition value. 
				
				hashobj.putAll(ConvertToLower.convertHashKey(hashobj));
				tdid=hashobj.get("id").toString();
				hashobj.remove("Id");
				hashobj.putAll(gin.CheckFromMaster(hashobj,process));
				
				//presentproperty is a generated message of the transaction_details according to the hashobj.  
				
				presentproperty=msg.convertToMessage(td_tableName, process, hashobj);
				Td_property_details Tdpl;				
				Tdpl = new Td_property_details(sqlDB);
				Tdpl.setProcess(process);
				Tdpl.setTdid(tdid);
				TransMap.put("tdid", tdid); 
				Enumeration< Object> enum1 = hashobj.keys();
				Hashtable<Object, Object> table =new Hashtable<Object, Object>();
				while(enum1.hasMoreElements())
				{
					String key=enum1.nextElement().toString();
					String value =hashobj.get(key).toString();
					Field.append(value+"\t");
					if(!Heading.contains(key))
						Heading.add(key);
				}
				
				try {
					sbrProperty = (Tdpl.getView());
					String tpdlheading[]  = sbrProperty.toString().split("\n");
					String splitheading[]=tpdlheading[0].split("\t");
					for(int k=0;k<splitheading.length;k++)
					{
						if(!Heading.contains(splitheading[k]))
							Heading.add(splitheading[k]);
					}
					
					Field.append(tpdlheading[1]+"\n");
				}
				catch (Exception e) 
				{
					e.printStackTrace();
				}
				
				
		}
		for(int k=0;k<Heading.size();k++)
		{
			heading.append(Heading.get(k)+"\t");
		}
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","getView",t.duration());
		return heading.append("\n"+Field);
	}
	
	
	
	public Hashtable<Object, Object> getBasicHashtable() 
	{
		return (TransactionDetailMap);
	}
	
	public boolean getResult() 
	{
		return flagResult;
	}
	public String getType() 
	{
		ExecutionTimer t = new ExecutionTimer();
		t.start();
		try 
		{
			return gin.getId((TransactionMap.get("transaction_type").toString()));
		} 
		catch (Exception e) 
		{
			String ttype="";
			try 
			{
				if(TransactionDetailMap.containsKey("tid"))
					ttype =TransactionDetailMap.get("tid").toString();
				else if(TransactionMap.containsKey("id"))
					ttype =TransactionMap.get("id").toString();;	
			ResultSet rs = sqlDB.getSelect("select transaction_type from "+masterTable+" where id ='"+ttype+"'" );
			if(rs.next())
					ttype = rs.getString("transaction_type");
			}
			catch (Exception e1) 
			{
				e1.printStackTrace();
			}
			t.end();
			@SuppressWarnings("unused")
			TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","getType",t.duration());
			return ttype;
		}
	}
	
	
	public void setPropertyVector(Vector<Object> propertydetails) 
	{
		ExecutionTimer t = new ExecutionTimer();
		t.start();
		this.PropertyList.addAll(propertydetails);
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","setPropertyVector",t.duration());
	}
	
	public void setTid(String tid)
	{	
		if(TransactionMap.isEmpty())
		{	
			try {	
					TransactionMap=sqlDB.getSelect("select * from transaction where id='"+tid+"'",1);
					TransactionMap = gin.ConvertvalueToMasterName(TransactionMap,"add","transaction");
					if(directRequest)
						TransMap.putAll(TransactionMap);
			} catch (Exception e) {
			
				e.printStackTrace();
			}
		}
		 this.tid = tid;
	}
	
	public void setDirectRequestflag(boolean directRequest)
	{
		this.directRequest = directRequest;
	}
	
	
	public void setTransactionMap(Hashtable<Object, Object>TransactionMap)
	{
		ExecutionTimer t = new ExecutionTimer();
		t.start();
		this.TransactionMap.putAll(TransactionMap);
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","setTransactionMap",t.duration());
	}
	
	
	public void setHashtable(Hashtable<Object, Object> table) 
	{	
		ExecutionTimer t = new ExecutionTimer();
		t.start();
		this.TransactionDetailMap = table;
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","setHashtable",t.duration());
	}
	
	
	public void setTransMap(Hashtable<Object, Object> transactionHash)
	{
		ExecutionTimer t = new ExecutionTimer();
		t.start();
		this.TransMap=transactionHash;
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","setTransMap",t.duration());
		
	}
	
	public void setProcess(String tempProcess) 
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		process = tempProcess;
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Master_table","setProcess",t.duration());
	}
	
	
	@Override
	public StringBuffer getDelete() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	public void setNewPropertyVector(Vector<Object> NewPropertyVector)
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		this.NewTransDetailVector = NewPropertyVector;	
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Property_details","setNewPropertyVector",t.duration());
	}
	
	
	public void setOldPropertyVector(Vector<Object> OldPropertyVector)
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		this.OldTransDetailVector = OldPropertyVector;	
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Property_details","setOldPropertyVector",t.duration());
	}
	
	public void setViewHashtable(Hashtable<Object,Object> hashtable) {
		ViewHashtable.putAll(hashtable);
	}
	
	/*private void calculateAmount()   //Processes for rate calculations of the transaction detail
	{
		ExecutionTimer t = new ExecutionTimer();
		t.start();
		TransactionDetailMap = gin.Convertno$ToZero(TransactionDetailMap);
		TransactionMap = gin.Convertno$ToZero(TransactionMap);
		TransactionDetailMap = ConvertToLower.convertHashKey(TransactionDetailMap);
		Calculation calc = new Calculation(td_tableName, sqlDB, ConvertToLower.convertHashKey(TransactionMap), ConvertToLower.convertHashKey(TransactionDetailMap));
		
		TransactionDetailMap.putAll(calc.getResult());
		t.end();
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","calculateAmount",t.duration());
	}*/
	
	/*public StringBuffer getView()
	{
		
		ExecutionTimer t = new ExecutionTimer();
		t.start();
		
		StringBuffer sbrProperty=new StringBuffer();
		MessageGenerator msg=new MessageGenerator(sqlDB);
		String mastermsg="";		
		
		//TransactionDetailMap stores all the input information given in the  request e.g tid(transaction id),item,qty,rate,amount 
		
		Command cp = new Command(td_tableName, sqlDB);
		TransactionDetailMap = cp.getHashCommand(td_tableName,message,process); 
		if(TransactionDetailMap.containsKey("ErrorInput"))
		{
			sbrProperty.append(TransactionDetailMap.get("ErrorInput"));
			return sbrProperty;
		}
			
		//TransMap is set from the transation table which contain an id of transaction only if the request is for  transaction 
		//and there is a direct request to the transaction_details then it shows empty TransMap. 
				
		Hashtable<Object, Object> TradMap= new Hashtable<Object, Object>();
		TradMap.putAll(TransactionDetailMap);
		TradMap=gin.removeDuplFromhash(TransMap,TradMap);
		
		//removed the fields through the TransactionMap which is already presents in the TransMap  through the removeDuplFromhash method.
					
		Hashtable<Object, Object> MastrMap= new Hashtable<Object, Object>();
		if(TradMap.isEmpty()==false)
		{
			
			MastrMap.putAll(TransactionDetailMap);
			
			if(MastrMap.containsKey("tid"))
			{
				MastrMap.put("id", MastrMap.get("tid"));
				MastrMap.remove("tid");				
			}			
		}
		else
		{
			sbrProperty.append("check condition");
			return sbrProperty;
		}
		
		TransactionDetailMap.putAll(gin.convertMasterId(TransactionDetailMap, td_tableName, process));
		
		//Master contain an tid in case of direct request to the transaction_details and shows empty in case of request is 
		//through the transaction.		
		
		mastermsg=msg.MasterMessage(masterTable, MastrMap, process);	
		
		TransactionDetailMap = gin.getHashMapOfValues(TransactionDetailMap);
		
		//According to the TransactionDetailMap getSelectVector method checks the condition ,searches all the record 
		//in transaction_details table  and stores into the vrs vector.
				
		Vector<Object> vrs  = new Vector<Object>(); 
			vrs.addAll(sqlDB.getSelectVector(TransactionDetailMap, td_tableName));			 
	
		String tdid="";
		
		//For the wrong input to the trans_property_details request it shows empty records.
		
		if(vrs.isEmpty())
		{
			sbrProperty.append("Record not available");
			return sbrProperty;
		}
		
		for(int i=0;i<vrs.size();i++)
		{
				
				String presentproperty="";
				Hashtable<Object, Object> hashobj=new Hashtable<Object, Object>();
				hashobj=(Hashtable<Object, Object>) vrs.get(i);
				
				//hashobj contain whole record (e.g tid,item,rate,qty,amount) which has taken through the database 
				//or transaction_details table according to the condition value. 
				
				hashobj.putAll(ConvertToLower.convertHashKey(hashobj));
				tdid=hashobj.get("id").toString();
				hashobj.remove("Id");
				hashobj.putAll(gin.CheckFromMaster(hashobj,process));
				
				//presentproperty is a generated message of the transaction_details according to the hashobj.  
				
				presentproperty=msg.convertToMessage(td_tableName, process, hashobj);
				Td_property_details Tdpl;
				Tdpl = new Td_property_details(sqlDB,message,process,Request);
				Tdpl.setTdid(tdid);
				TransMap.put("tdid", tdid); 
				
				sbrProperty.append(mastermsg+presentproperty);
				//Tdpl.setTransactionMap(TransMap);
				sbrProperty.append(Tdpl.getView());
		}
		t.end();
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","getView",t.duration());
		return sbrProperty;
	}*/

	/**
	 * In getupdate method of transaction_details  modify old item.
	 * getupdate contains oldTransactionMap and newTransactionMap.
	 * In oldTransactionMap it cointains id of the transaction as a tid
	 * old item,qty and in newtransactionMap contains new item,qty.
	 */
	
//	@Override
	/*public StringBuffer getUpdate() 
	{
		ExecutionTimer t = new ExecutionTimer();
		t.start();
        ResultSet rs = null;
        String spcharAdd = null;
        String propertyChar = null;
        Command cp = new Command(Request, sqlDB);
       
        Hashtable<Object,Object> newTransactionMap = new Hashtable<Object,Object>();
        Hashtable<Object,Object> oldTransactionMap = new Hashtable<Object,Object>();
        String msg = null;
        boolean flagReport = false;
        Vector<Object> pdbsNewVector = new Vector<Object>();
   		Vector<Object> pdbsOldVector = new Vector<Object>();

        ChekInMaster check = new ChekInMaster(sqlDB);
        try
        {
            rs = sqlDB.getSelect((new StringBuilder("select spchar from command where msgtype = '")).append(Request).append("' and process = 'add' order by order1").toString());
            rs.next();
            spcharAdd = rs.getString("spchar");
            rs.close();
         }
        catch(Exception e)
        {
            System.out.println("pool::MasterClass::getUpdate():: Exception while fatching special characters ");
            e.printStackTrace();
        }
        try
        {
            rs = sqlDB.getSelect((new StringBuilder("select fieldname,spchar,order1 from command where msgtype='")).append(Request).append("' and from_master='yes' and process='add' and order1>0 order by order1").toString());
            rs.next();
            propertyChar = rs.getString("spchar");
            rs.close();
        }
        catch(Exception e)
        {
            System.out.println("Pipe Char is not Found in Database");  //
        }
        int index = 0;
        
        int count = cp.getCountof(message, td_tableName, process);
        if(count != 0)
        {
            spChar = cp.getSPchar();
            index = Index.indexOf(message, spChar, index + 1);
        }
         tid = message.substring(0 ,index);
    	Hashtable<Object,Object> TempHash = new Hashtable<Object,Object>();
        TempHash = cp.getHashCommand(td_tableName,tid, "add");
		if(TempHash.containsKey("ErrorInput"))
	 	{
			return new StringBuffer(TempHash.toString());
		}
		tid = TempHash.get("tid").toString();
        
        oldTransactionMap.put("tid", tid);
        newTransactionMap.put("tid", tid);
        
        while(count != 0) 
        {
            if(index == -1)
                break;
            count--;
            try
            {
                int start = 0;TransactionDetailMap
                int end = 0;
                start = index;
                msg = message.substring(start+1);
                if(msg.contains(spChar))
                {
                    end = Index.indexOf(msg, spChar) + start;
                    msg = message.substring(start, end + 1);
                } 
                elseTransactionDetailMap
                {
                	
                	  msg = message.substring(start);
                
                }
                index = end + 1;
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            String msg1 = "";
            String msg2 = "";
            int start = 0;
            if(msg.contains(propertyChar))
            {
	            int end1 = 0;
	            end1 = Index.indexOf(msg, propertyChar, end1 + 1);
	            msg1 = msg.substring(start, end1);
	            newTransactionMap.putAll(cp.getHashCommand(td_tableName, msg1, process));
	            if(newTransactionMap.containsKey("ErrorInput"))
			 	{
					return new StringBuffer(newTransactionMap.toString());
				}
	            
	            start = Index.indexOf(msg, propertyChar, start + 1);
	            msg2 = msg.substring(start, msg.length());
	            oldTransactionMap.putAll(cp.getHashCommand(td_tableName, msg2, "add"));
	            if(oldTransactionMap.containsKey("ErrorInput"))
			 	{
					return new StringBuffer(oldTransactionMap.toString());
				}
            }
            else
            {
            	msg1=msg;
            	newTransactionMap.putAll(cp.getHashCommand(td_tableName, msg1, process));
            	if(newTransactionMap.containsKey("ErrorInput"))
			 	{
					return new StringBuffer(newTransactionMap.toString());
				}
            }
            oldTransactionMap = ConvertToLower.convertHashKey(oldTransactionMap);
            oldTransactionMap = gin.convertMasterId(oldTransactionMap, td_tableName, "add");
            newTransactionMap = ConvertToLower.convertHashKey(newTransactionMap);
            newTransactionMap = gin.convertMasterId(newTransactionMap, td_tableName, "add");
          
            try 
			{
			  	Hashtable<Object, Object> temp = new Hashtable<Object, Object>();
			  	Hashtable<Object, Object> temp1 = new Hashtable<Object, Object>();
          		try 
				{
          			temp = sqlDB.getSelectCheck(oldTransactionMap,td_tableName);
					if (temp.containsKey("Error")) 
					{
						return new StringBuffer(temp.toString());
					}
					temp = ConvertToLower.convertHashKey(temp);
				} catch (Exception e) {
				}
			  	temp1.putAll(temp);
			  	temp1.putAll(oldTransactionMap);
				oldTransactionMap = temp1; 
					
            	temp.putAll(newTransactionMap);
            	newTransactionMap.clear();
            	newTransactionMap.putAll(temp);
            }
			catch (Exception e)
			{
			}
		
           	if (check.isInProperty_details(oldTransactionMap,td_tableName) == false)
			{
				sbrDTB.append("Old Property Not Present ");
				System.out.println("Old Property Not Present ");
				sqlDB.pLog.Logger.append("\n Old Property Not Present ");
			}
			if (check.isInProperty_details(newTransactionMap,td_tableName) == true)
			{
				sbrDTB.append(" pool::PropertyDetails ::getUpdate():: New and Old Property are same ");
				System.out.println("pool::PropertyDetails ::getUpdate():: New and Old Property are same ");
				sqlDB.pLog.Logger.append("\n New and Old Property are same ");
			}
			
            if(check.isInProperty_details(newTransactionMap,td_tableName) == false && check.isInProperty_details(oldTransactionMap,td_tableName) == true )
			{	
            	
                ////////////////////////////////////
            	//newTransactionMap.put("amount", Integer.valueOf(0));
            	//newTransactionMap.put("rate", Integer.valueOf(0));
    	        //////////////////////////////////////
    	       
                
           		int j=sqlDB.getUpdate(Request, newTransactionMap, oldTransactionMap);
           		if(j>0)
	       		{
	       			sqlDB.pLog.Logger.append("\n "+ Request +" updated Success fully........ ");						
					sbrDTB.append(" updated Success fully........ ");
					
	       		}
           		pdbsOldVector.add(oldTransactionMap); // It will create the vector for the Old property.
    			pdbsNewVector.add(newTransactionMap); // It will create the vector for the New property.
    			flagReport = true;
           		getDetailHashtabel
           	}	
           // int j = sqlDB.getUpdate(Request, newTransactionMap, oldTransactionMap);
        }
        if(flagReport == true)
		{
			setVector(pdbsNewVector, pdbsOldVector);
			Request = td_tableName;
			getReport();
			PropertyDetailsBasicReports pdbs = new PropertyDetailsBasicReports(pdbsOldVector,sqlDB,process);
			pdbs.updateReport(pdbsNewVector);
		}
        t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Transaction_details","getUpdate",t.duration());
        return sbrDTB;
	}*/
	
	public Hashtable<Object, Object> getDetailHashtabel() 
	{
		return (TransactionDetailMap);
	}
	public Hashtable<Object, Object> getHashtabel() 
	{
		/*Hashtable<Object, Object> temp = new Hashtable<Object, Object>();
		Hashtable<Object, Object> temp1 = new Hashtable<Object, Object>();
		temp.putAll(TransactionDetailMap);
		temp1.putAll(gin.ConvertvalueToMasterName(temp,process,"transaction_details"));
		temp.clear();
		temp.putAll(gin.ConvertKeytoMasterId(temp1));
		TransactionDetailMap.clear();
		TransactionDetailMap.putAll(temp);*/
		return TransactionDetailMap;
	}
	public String getProceess() 
	{
		return null;
	}
	public  void settplVector(Vector<Object>propertydetails)
	{
		this.TPlPropertyList = propertydetails;
	}
	
	public Vector<Object> getpropertyVector() 
	{
		return new Vector<Object>();
	}
	 public  Vector<Object> gettplVector()
	 {
		   return TPlPropertyList; 	 
	 }
		
	public String getTable() 
	{
		return td_tableName;
	}
	
	public Hashtable<Object,Object> getmasterHashtabel()
	{
		return ConvertToLower.convertHashKey(TransactionMap);
	}
	
	public void setmasterHashtabel(Hashtable<Object,Object> table)
	{
	 this.TransactionMap = table;	
	}
	
	@SuppressWarnings("unchecked")
	public Hashtable<Object ,Object> process()
	{
		ExecutionTimer t = new ExecutionTimer();
		t.start();
		Hashtable< Object, Object>error  =new Hashtable<Object, Object>();
		if(PropertyList.size()>0)
		{
				Transaction_details td = (Transaction_details) PropertyList.get(0);
				td.setRequestParameter(reqParam);
				this.TransactionDetailMap.putAll(td.TransactionDetailMap);
		}
		if(reqParam.getRequest().equalsIgnoreCase(td_tableName))
		{
			Basicprocess basicprocess; 
			//BASIC PROCESS LIKE INHERITANCE
			basicprocess = new Basicprocess(); 
			basicprocess.setDbmanager(sqlDB);
			basicprocess.setObject(this);
			basicprocess.processBasicprocess();
			basicprocess.getInsert();
			error = basicprocess.getHashtable();
			if(error.containsKey("ErrorInput"))
			{
				return error;
			}
		}	
		for(int i=0;i<PropertyList.size();i++)
		{	
			Transaction_details td = (Transaction_details) PropertyList.get(i);		
			this.TransactionDetailMap.putAll(gin.convertMasterName(td.TransactionDetailMap, td_tableName,process));
			
			//this.TransactionDetailMap.putAll(td.TransactionDetailMap);
			//PREPROCESS LIKE VALIDATION
			Preprocess preprocess = new Preprocess();
			preprocess.setDbmanager(sqlDB);
			preprocess.setObject(this);
			preprocess.ProcessPreprocess();
			error = preprocess.gethashtable();
			if(error.containsKey("ErrorInput"))
			{
				try 
				{
					ErrorMap.clear();
					Hashtable< Object, Object>TEMP = (Hashtable<Object, Object>) error.get("ErrorInput");
					System.out.println("The temp Map is  "+TEMP);
					System.out.println("The temp value Map is  "+TEMP.values());
					ErrorMap.put("ErrorInput",TEMP.values());
					System.out.println("The Error Map is  "+ErrorMap);
					return  ErrorMap;
				}
				catch (Exception e) 
				{
					return error; 
				}
			}
			else
				td.TransactionDetailMap.putAll(this.TransactionDetailMap);
		}
		System.out.println("The Error Hash Tabel :"+error);
		Hashtable<Object ,Object> ErrorMap=new Hashtable<Object, Object>();
		
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Master_table","validate",t.duration());
		return ErrorMap;
	}
	
	public void setTransactionMap() 
	{
		Hashtable<Object, Object> condition =new Hashtable<Object, Object>();
		condition.put("id",tid);
		Vector<Object>Transactionvector=sqlDB.getSelectVector(condition,"transaction");
		if(Transactionvector.size()>0)
		{	
			TransactionMap.putAll(gin.ConvertValuetoMasterName(((Hashtable<Object, Object>) Transactionvector.get(0)),reqParam.getProcess(),"transaction"));
		}	
	}
	public void transactionPreProcess()
	{
		Transaction transaction = new Transaction(sqlDB);
		transaction.setmasterHashtabel(TransactionMap);
		transaction.setPropertyVector(PropertyList);
		RequestParameter req=reqParam;  
		req.setRequest(masterTable);
		transaction.setRequestParameter(req);
		transaction.process();
	}
}
